import {Component} from '@angular/core';
import {NavController, NavParams} from 'ionic-angular';

import {Backend} from '../../providers/backend';
import {Meetingpayment} from './tab-meeting-payment';
import {Conference} from '../tab-my/tab-my-conference';
import {Information} from '../tab-my/tab-my-information';

@Component({
  templateUrl: 'build/pages/tab-events/tab-meeting-signup.html'
})
export class Meetingsignup {

  static get parameters() {
    return [[NavController], [NavParams], [Backend]];
  }

  constructor(nav, params, backend) {
    this.nav = nav;
    this.params = params;
    this.backend = backend;
    this.email = params.get('email');
    this.uid = params.get('uid');
    this.id = params.get('id');
    this.name;
    this.itype;
    this.jobtitle;
    this.phone;
    this.cname;
    this.price;
    this.rmb;
    this.retime;
    this.tid;
    this.conference;
    this.contents;
    this.mcontents;
    
    this.Title;
    this.First_Name;
    this.Last_Name;
    this.Mobile_Number;
    this.Industry_Type;
    this.Company_Name;
    this.Department;
    this.Job_Title;
    this.uid;
console.log(this.id);
    this.backend.loginsuccess()
      .then(result => {
        this.contents = result.result[0];
        console.log(this.contents,111);
        this.name = this.contents.fname + this.contents.lname;
        this.itype = this.contents.itype;
        this.jobtitle = this.contents.jobtitle;
        this.phone = this.contents.phone;
        this.Title = this.contents.title;
        this.First_Name = this.contents.fname;
        this.Last_Name = this.contents.lname;
        this.Mobile_Number = this.contents.phone;
        this.Industry_Type = this.contents.itype;
        this.Company_Name = this.contents.company;
        this.Department = this.contents.department;
        this.Job_Title = this.contents.jobtitle;
        this.uid = this.contents.userid;
      });
    this.backend.meetingdetails(this.id)
      .then(result => {
        console.log(result,222);
        this.mcontents = result.result[0];
        console.log(this.mcontents,333);
        this.cname = this.mcontents.title;
        this.price = this.mcontents.payinfo.price;
        this.rmb = this.mcontents.payinfo.rmb;
        this.retime = this.mcontents.registration_start_time;
        this.tid = this.mcontents.oid;
      });
    this.backend.isLogined()
      .then(result => {
        this.result = result;
        console.log(this.result);
        this.email = this.result.email;
        this.uid = this.result.uid;
      });


  }
  signup(price,rmb) {
    this.backend.signup(this.email, this.id)
      .then(result => {
        this.status = result.status;
        console.log(this.status);
        this.act;
        console.log(rmb);
        if (rmb == '0.00'||rmb == 0.00) {
          if (this.status == 3) {
            this.act = 'oldaddOrder';

          } else if (this.status == 2) {
            this.act = 'addOrder';
          }
          this.backend.addorder(this.act, this.email, this.id, this.Title, this.First_Name, this.Last_Name, this.Mobile_Number, this.Industry_Type, this.Company_Name, this.Department, this.Job_Title)
            .then(result => {
              this.result = result;
              console.log(this.result);
              if (this.result.status == 1) {
                this.nav.push(Conference);
              }
            });

        } else {
          if (this.status == 3) {
            this.act = 'oldaddOrder';

          } else if (this.status == 2) {
            this.act = 'addOrder';
          }
          this.backend.addorder(this.act, this.email, this.id, this.Title, this.First_Name, this.Last_Name, this.Mobile_Number, this.Industry_Type, this.Company_Name, this.Department, this.Job_Title)
            .then(result => {
              this.result = result;
              console.log(this.result);
              if (this.result.status == 1) {
                 this.backend.conference(this.uid)
          .then(result => {
            this.conference = result.data[0];
            console.log(this.conference);
            this.oid=this.conference.id;
            this.nav.push(Meetingpayment,{'price':price,'rmb':rmb,'oid':this.oid});
          });
                
              }
            });
        }


      });

  }
edit(){
    this.backend.isLogined()
      .then(result => {
        this.result = result;
        console.log(this.result);
        this.email = this.result.email;
        this.uid = this.result.uid;
       
      });
  this.nav.push(Information, { email: this.email, uid: this.uid });
}
}
